package com.imooc.distributedemo.resume.leetcode;

/**
 * leetcode121 买卖股票的最佳时间
 */
public class Solution121 {
    public static void main(String[] args) {
//        int[] prices = {7,1,5,3,6,4};
        int[] prices = {7,2,5,3,2,1};
        int j = maxProfit(prices);
        System.out.println(j);
    }

    public static int maxProfit(int[] prices) {
        if(null==prices||prices.length<1){
            return 0;
        }
        int diff=0;
        for (int i = 0; i < prices.length-1; i++) {
            for (int j = i; j < prices.length; j++) {
                int num = prices[j]-prices[i];
                diff=Math.max(num,diff);
            }
        }
        return diff>0?diff:0;
    }
}
